<?php

abstract class View
{
	private $markup;
	
	protected $messages = array();
	protected $errors = array();
	
	final public function __construct()
	{
		$this->markup = '';
	}
	
	final public function Markup( $str = false )
	{
		if ( $str === false )
		{
			return $this->markup;
		}
		else
		{
			$this->markup .= $str;
		}
	}
	
	final public function GetAction()
	{
		return isset( $_GET['a'] ) ? $_GET['a'] : null;
	}

	final public function Message( $msg ) {
		$this->messages[] = $msg;
	}
	
	final public function Error( $msg )
	{
		$this->errors[] = $msg;
	}
	
	final public function HasErrors()
	{
		return !empty( $this->errors );
	}

	final public function PrintErrors( $format )
	{
		foreach ( $this->errors as $error )
		{
			$this->Markup( str_replace( "_ERROR_", $error, $format ) );
		}
	}

	final public function PrintMessages( $format )
	{
		foreach ( $this->messages as $message )
		{
			$this->Markup( str_replace( "_MESSAGE_", $message, $format ) );
		}
	}
}
